package com.liyu.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Collections;

/**
 * @author 李誉
 * @date 2022-07-04 21:39
 * @description
 */
@Component
public class DirectComment {

    public static final String DIRECT_EXCHANGE = "direct.ex.hello";

    public static final String DIRECT_QUEUE = "direct.queue.hello";

    public static final String DIRECT_RK = "direct.rk.hello";


    /**
     * 声明交换机
     * @return 交换机
     */
    @Bean("directExchange")
    public Exchange directExchange() {
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    /**
     * 声明队列
     * @return 队列
     */
    @Bean("directQueue")
    public Queue directQueue() {
        return new Queue(DIRECT_QUEUE);
    }

    /**
     * 绑定队列和交换机
     * @param directQueue 队列
     * @param directExchange 交换机
     * @return 绑定关系
     */
    @Bean("directBinding")
    public Binding directBinding(Queue directQueue, Exchange directExchange) {
        return BindingBuilder.bind(directQueue).to(directExchange).with(DIRECT_RK).and(Collections.emptyMap());
    }
}
